package com.dinner.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dinner.entity.DiOrder;
import com.dinner.mapper.DiOrderMapper;
import com.dinner.mapper.DiUserMapper;
import com.dinner.service.DiOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dinner
 * @since 2022-02-13
 */
@Service
public class DiOrderServiceImpl extends ServiceImpl<DiOrderMapper, DiOrder> implements DiOrderService {

    @Autowired
    DiOrderMapper diOrderMapper;
    @Autowired
    DiUserMapper diUserMapper;

    public List<DiOrder> findOrderAll(int size, int current) {
        Page<DiOrder> page=new Page<>(size,current);
        Page<DiOrder> pages=diOrderMapper.selectPage(page,null);
        List<DiOrder> list=pages.getRecords();
        for(DiOrder a:list){
            a.setDiUser(diUserMapper.selectById(a.getUserId()));
        }
        return list;

    }

    @Override
    public List<DiOrder> findOrderByUserId(int size, int current, int userId) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("user_id",userId);
        Page<DiOrder> page=new Page<>(size,current);
        Page<DiOrder> pages=diOrderMapper.selectPage(page,wrapper);
        List<DiOrder> list=pages.getRecords();
        for(DiOrder a:list){
            a.setDiUser(diUserMapper.selectById(a.getUserId()));
        }
        return list;
    }
}
